package com.kedacom.ctsp.authority.entity;

import com.kedacom.ctsp.lang.mapper.CollComponentType;
import com.kedacom.ctsp.web.entity.AbstractCrudEntity;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Set;

/**
 * 用户
 *
 * @author sunchenjie
 */
@Data
@Entity
@Table(name = "user")
public class SimpleUser extends AbstractCrudEntity<String> implements User, ExtendedBean {

    /**
     * 主键id ，自增长
     */
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    private String id;

    @Column
    private String name;

    @Column(unique = true)
    private String username;

    @Column
    private String password;
    /**
     * 扩展字段
     */
    @Column(length = 4000)
    private String extendedField;

    /**
     * 角色
     */
    @CollComponentType(Role.class)
    @ManyToMany(fetch = FetchType.EAGER, targetEntity = SimpleRole.class)
    @JoinTable(name = "user_role", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private Set<Role> roles;

    /**
     * 人员
     */
    @OneToOne(targetEntity = SimplePerson.class)
    @JoinColumn(name = "person_id")
    private Person person;
}
